import Config from './Config.js'

class Bubble {
  constructor({ id = 0, cx, cy, r = Config.defaultRadius, fillColor = "#fff", state = 0 }) {
    // id
    this.id = id;
    // x轴
    this.cx = cx;
    // y轴
    this.cy = cy;
    // 半径
    this.r = r;
    // 填充颜色
    this.fillColor = fillColor;
    // 状态 0 正常，1 被点击
    this.state = state;
  }

  // 渲染函数
  render(context) {
    context.beginPath();
    // 画出单个泡泡
    context.arc(this.cx, this.cy, this.r, 0, Math.PI * 2);
    let g = context.createRadialGradient(this.cx, this.cy, 0, this.cx, this.cy, this.r);
    g.addColorStop(0, "#ddd");
    g.addColorStop(1, this.fillColor);
    context.fillStyle = g;
    context.shadowColor = this.fillColor;
    context.shadowBlur = 10;
    context.fill();
    context.closePath();
  }

}

export default Bubble;
